package top.dark.persist;

import org.apache.activemq.ActiveMQConnectionFactory;

import javax.jms.*;

/**
 * Author: Darkn
 * description:
 * Create Time: 2021/5/4 16:24
 */
public class JmsProducer {
    private static final String ACTIVEMQ_URL = "tcp://192.168.136.181:61616";
    private static final String ACTIVEMQ_TOPIC01 = "persist_topic01";
    public static void main(String[] args) throws JMSException {
        ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(ACTIVEMQ_URL);
        Connection connection = factory.createConnection();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(ACTIVEMQ_TOPIC01);
        MessageProducer producer = session.createProducer(topic);
        producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
        connection.start();

        for (int i = 0; i < 6; i++) {
            TextMessage textMessage = session.createTextMessage("persist_topic01 ------" + i);
            producer.send(textMessage);
        }

        System.out.println("--------------persist_topic生产完成。。。。。。");
        producer.close();
        session.close();
        connection.close();
    }
}
